﻿
using System;
using System.Diagnostics.Contracts;

namespace Isuka.Excel
{

    public enum XDirection
    {
        Down = -4121,       // XlDirection.xlDown,
        ToLeft = -4159,     // XlDirection.xlToLeft,
        ToRight = -4161,   // XlDirection.xlToRight,
        Up = -4162,        // XlDirection.xlUp,
    }

    public static class XConstants
    {
        public static bool IsVirtical(this XDirection dir)
        {
            return dir == XDirection.Up || dir == XDirection.Down;
        }

        public static bool IsHorizontal(this XDirection dir)
        {
            return dir == XDirection.ToLeft || dir == XDirection.ToRight;
        }

        public static int Distance(this XDirection dir, XRange x, XRange y)
        {
            Contract.Requires<ArgumentNullException>(x != null, "x");
            Contract.Requires<ArgumentNullException>(y != null, "y");

            if (dir == XDirection.Down)
                return y.Row - x.Row;
            else if (dir == XDirection.ToLeft)
                return -(x.Column - y.Column);
            else if (dir == XDirection.ToRight)
                return y.Column - x.Column;
            else
                return -(x.Row - y.Row);
        }
    }
}
